import type { AppRouteModule } from "@/router/types";

import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import { LoginRoute } from "./constant";

const modules = import.meta.glob("./modules/**/*.ts", { eager: true });
const asyncRoutes: AppRouteModule[] = [];
Object.keys(modules).forEach((key) => {
  // @ts-ignore
  const module = modules[key].default || {};
  const moduleList = Array.isArray(module) ? module : [module];
  asyncRoutes.push(...moduleList);
});


// const constantRoutes: AppRouteModule[] = [LoginRoute];

const routes = [LoginRoute, ...asyncRoutes];
// console.log(routes);

// const routes: Array<AppRouteModule> = [
//   {
//     path: "/",
//     name: "Login",
//     component: () => import("@/views/login/index.vue"),
//     meta: {
//       title: "登录",
//       // hidden: true,
//     },
//   },
//   {
//     path: "/index",
//     name: "Index",
//     component: () => import("@/layout/index.vue"),
//     meta: {
//       title: "首页",
//       // hidden: false,
//     },
//   },
// ];

const router = createRouter({
  history: createWebHistory(),
  routes: routes as unknown as RouteRecordRaw[],
});

export default router;
